import os
import shutil

def get_dlist_infolder(root_path):
	dlist = []
	for d in os.listdir(root_path):
		if d == '.' or d == '..':
			continue
		if os.path.isdir(d):
			dlist.append(os.path.join(root_path, d))
	return dlist

def get_flist_infolder(root_path):
	flist = []
	for f in os.listdir(root_path):
		fpath = os.path.join(root_path, f)
		if os.path.isfile(fpath):
			flist.append(os.path.join(root_path, f))
	return flist

def rm_emptydirs(root_path):
	for d in get_dlist_infolder(root_path):
		subdir = os.path.join(root_path, d)
		flist = get_flist_infolder(subdir)
		if len(flist) < 1:
			print('removing subdir %s' % subdir)
			os.rmdir(subdir)
		else:
			print('%s\t%d files' % (subdir, len(flist)))

root_path = '/home/youngway/downloads'
rm_emptydirs(root_path)